/*
 * @Author: yanjikun
 * @Date: 2021-11-04 17:17:39
 * @LastEditors: yanjikun
 * @LastEditTime: 2022-06-16 11:29:47
 * @Description: file content
 */
import { generatorDynamicRouter } from '@/router/generator-routers'
import { defineStore } from 'pinia'
import { RouteRecordRaw } from 'vue-router'
const AsyncRouteState = {
  menus: [] as RouteRecordRaw[],
}
type IAsyncRouteState = typeof AsyncRouteState
export const useAsyncRoute = defineStore({
  id: 'async-route',
  state: (): IAsyncRouteState => AsyncRouteState,
  getters: {
    getMenus(): () => IAsyncRouteState['menus'] {
      return () => this.menus
    },
  },
  actions: {
    setMenus(routers: RouteRecordRaw[]) {
      this.menus = routers
    },
    async generateRoutes() {
      const routers = await generatorDynamicRouter()
      this.setMenus(routers)
      return routers
    },
  },
})
